<template>
	<view class="container" :data-theme="theme">
		<view class="header"><!-- 商品详情 -->
			<view class="gift-type-card" v-if="goodsOrCategoryInfo && goodsOrCategoryInfo.id">
				<view class="gift-type" style="display: flex;justify-content: space-between;align-items: center;">
					<view class="gift-type-left">
						开启状态
					</view>
					<view class="gift-type-right">
						<switch :checked="checkedObj.isShow" @change="changeIsShow" />
					</view>
				</view>
			</view>
			<view class="gift-type-card" v-if="goodsOrCategoryInfo && goodsOrCategoryInfo.id">
				<view class="gift-type" style="display: flex;justify-content: space-between;align-items: center;">
					<view class="gift-type-left">
						商品/品类信息
					</view>
					<view class="gift-type-right">
						<button :style="{color: bgColor,}" @click="handleDetail">查看详情</button>
					</view>
				</view>
			</view>

		</view>
		<view class="content">
			<!-- 这里是可滚动的内容 -->
			<scroll-view class="scroll-view" scroll-y>
				<view class="scroll-view-inner">
					<!-- 售卖区域 -->
					<view class="sale-area-card">
						<view class="sale-area">
							<view class="sale-area-left">售卖区域</view>
							<view class="sale-area-right">
								<uni-data-picker placeholder="请选择售卖区域" popup-title="请选择所在地区" :localdata="cityCodeList"
									v-model="classes" @change="onchange">
								</uni-data-picker>
								<!-- <picker @change="saleAreaChange" @cancel="saleAreaCancel" @click="saleAreaCancel"
									:value="saleAreaIndex" :range="saleAreaList" range-key="name"
									style="display: flex;">
									<view style="display: flex;">
										<view style="font-size: 14px;margin-right: 6rpx;" v-if="isShowSaleArea">请选择
										</view>
										<view style="font-size: 14px;margin-right: 6rpx;" v-else='isShowSaleArea'>
											{{ saleAreaList[saleAreaIndex].name }}
										</view>
										<u-icon name="arrow-right"></u-icon>
									</view>
								</picker> -->
							</view>
						</view>
					</view>
					<!-- 商品活动 -->
					<view class="product-active-card">
						<!-- 活动时间 -->
						<view class="active-time">
							<view class="active-time-left">活动时间</view>
							<view class="active-time-right">
								<uni-datetime-picker v-model="depreciatePromotion.activityTimeList" type="daterange"
									@change="changeActiveTime">
									<view v-if="depreciatePromotion.activityTime">{{depreciatePromotion.activityTime}}
									</view>
									<view v-else>请选择活动时间</view>
								</uni-datetime-picker>
								<u-icon name="arrow-right"></u-icon>
							</view>
						</view>
						<!-- 商品范围 -->
						<view class="product-scope">
							<view class="product-scope-left">商品范围</view>
							<view class="product-scope-right">
								<view class="product-type" :class="{'active' : index == productScopeIndex}"
									v-for="(item,index) in productScopeList" :key="index"
									@click="clickProductType(index)">
									{{item.name}}
								</view>
							</view>
						</view>
						<!-- 单客户限购单数 -->
						<view class="active-limit-card">
							<view class="active-limit-top">
								<view class="active-limit-left">单客户限购单数 <uni-icons type="info" size="20"></uni-icons>
								</view>
								<view class="active-limit-right">
									<view class="active-type" :class="{'active' : index == dateLimitShopIndex}"
										v-for="(item,index) in dateLimitShopList" :key="index"
										@click="clickDateLimitShop(index)">
										{{item.name}}
									</view>
								</view>
							</view>
							<view class="active-limit-bottom" v-if="dateLimitShopIndex == 1">
								<uni-number-box v-model="depreciatePromotion.activeLimit.dateLimitShopNum" />
							</view>
						</view>
						<view class="active-limit-card">
							<view class="active-limit-top">
								<view class="active-limit-left">活动总限购单数 <uni-icons type="info" size="20"></uni-icons>
								</view>
								<view class="active-limit-right">
									<view class="active-type" :class="{'active' : index == totalOrderLimitIndex}"
										v-for="(item,index) in totalOrderLimitList" :key="index"
										@click="clickTotalOrderLimit(index)">
										{{item.name}}
									</view>
								</view>
							</view>
							<view class="active-limit-bottom" v-if="totalOrderLimitIndex == 1">
								<uni-number-box v-model="depreciatePromotion.totalOrderLimitObj.totalOrderLimit"
									:max="99999" :min="1" />
							</view>
							<!-- <view class="discounts-hint"
								v-if="depreciatePromotion.totalOrderLimitObj.totalOrderLimitIsShow">限单数必须小于99999
							</view> -->
						</view>
					</view>
					<!-- 优惠阶梯 -->
					<view class="discounts-card">
						<view class="discounts-item" v-for="(item,index) in depreciatePromotion.discountsList"
							:key="index">
							<view class="discounts-item-title">
								<view class="item-title-left">
									阶梯{{index + 1}}
								</view>
								<view class="item-title-right">
									<view class="price-left">
										<view class="price-num">
											<view>满</view>
											<input type="number" placeholder="请输入" v-model="item.condition"
												@input="fullInputMoneyNum(index)" class="right-input" />
										</view>
										<view class="price-num">
											<view>减</view>
											<input type="number" placeholder="请输入" v-model="item.subsidy"
												@input="discountInputMoneyNum(index)" class="right-input" />
										</view>
									</view>

									<view class="price-right"><u-icon name="trash-fill" size="26"
											v-if="depreciatePromotion.discountsList.length != 1"
											@click="handleDelete(index)"></u-icon></view>
								</view>
							</view>
							<!-- 金额满 -->
							<view class="discounts-hint" v-if="item.hintIsShow">
								{{item.hintInfo}}
							</view>
						</view>
						<!-- 新增阶梯 -->
						<view class="ladder-card font_color" @click="addLadder"
							v-if="depreciatePromotion.discountsList.length < 3">
							+新增阶梯{{depreciatePromotion.discountsList.length}}/3
						</view>
					</view>
				</view>
			</scroll-view>
		</view>
		<view class="footer">
			<checkbox-group @change="requiredChange">
				<label class="footer-required">
					<view>
						<checkbox :checked="required" />
					</view>
					<view>已阅读并同意 <span class="font_color">《合作商自营销协议》</span> </view>
				</label>
			</checkbox-group>

			<button class="bg_color" @click="handleNext" shape="circle"
				style="padding: 20rpx;">{{productScopeIndexObj[productScopeIndex]}}</button>
		</view>
	</view>
</template>
<script>
	import {
		setThemeColor
	} from '../../../utils/setTheme';
	import {
		queryBusinessOperateCityApi
	} from "@/api/operateCity.js"
	import {
		getCityTreeListApi,
		addActivityRegistrationApi,
		getNoRegistrationActivityApi
	} from "@/api/marketing.js"
	let app = getApp()
	export default {
		data() {
			return {
				bgColor: "#fff",
				theme: app.globalData.theme,
				depreciatePromotion: {
					activityTime: null, // 活动时间
					activityTimeList: [], // 活动时间
					saleAreaList: [], // 售卖区域
					activeLimit: {
						dateLimitShopNum: '', // 日限购 自定义数量
						dateLimitShop: true, // 日限购
					},
					totalOrderLimitObj: {
						totalOrderLimit: 1, // 活动总限购单数
						totalOrderLimitIsShow: false, // 活动总限购单数提示是否显示
					},
					// 优惠阶梯
					discountsList: [{
						condition: '', //金额满、件数
						type: 1, // 活动补贴type 1、满金额减 2、满金额扣减比例 3、满金额赠 4、满件数赠    传1
						subsidy: '', // 补贴：扣减金额、扣减比例、赠送件数
						hintIsShow: false, // 提示信息是否显示
						hintInfo: '', // 提示信息
					}],
				},
				// ----------------------------商品范围----------------------
				productScopeList: [{
						name: '全店',
						value: 0
					},
					{
						name: '部分商品',
						value: 1
					},
					{
						name: '部分品类',
						value: 2
					},
				],
				productScopeIndex: 0,
				productScopeIndexObj: {
					0: '确认创建',
					1: '下一步，选择门槛商品',
					2: '下一步，选择门槛品类',
				},
				// ----------------------------end----------------------
				// ----------------------------单客户限购单数----------------------
				dateLimitShopList: [{
						name: '不限制',
						value: 1
					},
					{
						name: '自定义',
						value: 2
					},
				],
				dateLimitShopIndex: 0,
				// ----------------------------end----------------------
				// ----------------------------活动总限购单数----------------------
				totalOrderLimitList: [{
						name: '不限制',
						value: 1
					},
					{
						name: '自定义',
						value: 2
					},
				],
				totalOrderLimitIndex: 0,
				// ----------------------------end----------------------
				required: false,
				configInfo: {}, // 活动配置信息
				// ------------------------------售卖区域-------------------
				cityCodeList: [], // 城市信息
				classes: null,
				// ----------------------------end----------------------------
				// ------------------------回显数据-------------------
				// 商品满赠信息
				goodsOrCategoryInfo: {},
				// 通用赠品信息
				generalGiftInfo: {},
				// 开启状态
				checkedObj: {
					isShow: false
				}
			}
		},
		onLoad(options) {
			this.bgColor = setThemeColor()
			uni.setNavigationBarColor({
				frontColor: '#ffffff',
				backgroundColor: this.bgColor,
			});
			// 获取售卖区域
			this.initData()
		},
		methods: {
			// 初始化数据
			initData() {
				this.getNoRegistrationActivity()
				this.getCityTreeList()
			},
			// 回显数据
			echoData() {
				// 开启状态
				this.$set(this.checkedObj, 'isShow', this.goodsOrCategoryInfo.isShow)
				// 回显时间
				let timeList = this.goodsOrCategoryInfo.activityTimeList
				this.depreciatePromotion.activityTimeList = timeList
				this.depreciatePromotion.activityTime = timeList[0].slice(0, 10) + '至' + timeList[1].slice(0, 10) + '(' +
					'共' +
					this
					.calculateDaysBetweenDates(timeList[0], timeList[
						1]) + '天)'
				this.productScopeIndex = this.goodsOrCategoryInfo.productScope
				// 单客户限购单数
				if (this.goodsOrCategoryInfo.customerDailyLimit == -1) {
					this.dateLimitShopIndex = 0
				} else {
					this.dateLimitShopIndex = 1
					this.$set(this.depreciatePromotion.activeLimit, 'dateLimitShopNum', this.goodsOrCategoryInfo
						.customerDailyLimit)
				}
				// 活动总限购单数
				if (this.goodsOrCategoryInfo.totalOrderLimit == -1) {
					this.totalOrderLimitIndex = 0
				} else {
					this.totalOrderLimitIndex = 1
					this.$set(this.depreciatePromotion.totalOrderLimitObj, 'totalOrderLimit', this.goodsOrCategoryInfo
						.totalOrderLimit)
				}
				// 售卖区域
				this.classes = this.goodsOrCategoryInfo.activityScopeList[0][1]
				this.depreciatePromotion.saleAreaList = this.goodsOrCategoryInfo.activityScopeList
				// 满赠优惠信息
				this.depreciatePromotion.discountsList = this.goodsOrCategoryInfo.activitySubsidyList.map(item => {
					return {
						condition: item.condition, //金额满
						type: item.type, // 活动补贴type 1、满金额减 2、满金额扣减比例 3、满金额赠 4、满件数赠    传1
						subsidy: item.subsidy, // 补贴：扣减金额、扣减比例、赠送件数
						hintIsShow: false, // 提示信息是否显示
						hintInfo: '', // 提示信息
					}

				})
			},
			// ------------------------------end----------------------------
			// 查看详情
			handleDetail() {
				uni.navigateTo({
					url: `/pages/marketing/fullDiscountList/components/productDetail?cityCodeList=${JSON.stringify(this.cityCodeList)}`,
				});
			},
			// -----------------------------售卖区域----------------------
			// 选择售卖区域城市
			onchange(e) {
				if (e.detail.value.length) {
					this.depreciatePromotion.saleAreaList = [
						[
							e.detail.value[0].value, e.detail.value[1].value
						]
					]
				}
			},
			calculateDaysBetweenDates(date1Str, date2Str) {
				// 将日期字符串转换为 Date 对象
				var date1 = new Date(date1Str);
				var date2 = new Date(date2Str);

				// 计算两个日期的时间戳（单位：毫秒）
				var time1 = date1.getTime();
				var time2 = date2.getTime();

				// 确保 date1 <= date2，如果不是，则交换两个日期
				if (time1 > time2) {
					var temp = date1;
					date1 = date2;
					date2 = temp;
				}

				// 设置 date1 的时分秒为 00:00:00
				date1.setHours(0, 0, 0, 0);

				// 设置 date2 的时分秒为 00:00:00，并将日期加一天，用于确保计算包含 date2 这一天
				date2.setHours(0, 0, 0, 0);
				date2.setDate(date2.getDate() + 1);

				// 计算两个日期之间的天数差
				var timeDiff = date2.getTime() - date1.getTime();
				var daysDiff = Math.floor(timeDiff / (1000 * 60 * 60 * 24));

				return daysDiff;
			},
			// 改变活动时间
			changeActiveTime(e) {
				this.depreciatePromotion.activityTime = e[0] + '至' + e[1] + '(共' + this.calculateDaysBetweenDates(e[0], e[
					1]) + '天)'
				this.depreciatePromotion.activityTimeList = [e[0] + ' 00:00:00', e[1] + ' 23:59:59']
			},
			// -----------------------------商品范围------------------
			clickProductType(index) {
				this.productScopeIndex = index
			},
			// 单客户限购单数
			clickDateLimitShop(index) {
				this.dateLimitShopIndex = index
			},
			// 活动总限购单数
			clickTotalOrderLimit(index) {
				this.totalOrderLimitIndex = index
			},
			// 满赠方式
			clickGiveMethods(index) {
				this.giveMethodsIndex = index
			},

			// -------------------------------优惠阶梯----------------------------------
			// 选择商品
			// index  商品选择范围
			selectionProduct(index) {
				this.generalGift()
				// 组合活动配置信息
				const activityTime = this.depreciatePromotion.activityTime.replace(/\(.*?\)/, "");
				this.configInfo = {
					activityTime,
					discountsList: this.depreciatePromotion.discountsList
				}
				// 删除部分品类
				let partCategoryList = []
				if (this.goodsOrCategoryInfo && this.goodsOrCategoryInfo.productScope == 2) {
					partCategoryList = this.goodsOrCategoryInfo
						.enrolledActivityProductVoList.map(item => {
							return {
								businessSign: 3,
								enrolledActivityId: item.enrolledActivityId
							}
						})
				}
				uni.navigateTo({
					url: `/pages/marketing/fullDiscountList/components/promotionProduct?productScopeIndex=${index}&configInfo=${JSON.stringify(this.configInfo)}&generalGiftInfo=${JSON.stringify(this.generalGiftInfo)}&partCategoryList=${JSON.stringify(partCategoryList)}`,
				})

			},
			// 优惠阶梯添加商品
			addDiscountsProduct(threeProductList) {
				this.depreciatePromotion.discountsList[threeProductList[0].discountsIndex].giftProductInfo =
					threeProductList[0]
				this.giftProductHint(threeProductList[0].discountsIndex)
				// 有商品将空商品校验取消
				this.depreciatePromotion.discountsList[threeProductList[0].discountsIndex].giftProductInfoDataShow = false
			},
			// 满金额事件
			fullInputMoneyNum(index) {
				setTimeout(() => {
					// 判断门槛金额需要随着阶梯增加而增加
					if (index >= 1) {
						if (Number(this.depreciatePromotion.discountsList[index].condition) <= Number(this
								.depreciatePromotion
								.discountsList[
									index - 1].condition) || Number(this.depreciatePromotion.discountsList[index]
								.subsidy) <=
							Number(this
								.depreciatePromotion.discountsList[index - 1].subsidy)) {
							this.depreciatePromotion.discountsList[index].hintIsShow = true
							this.depreciatePromotion.discountsList[index].hintInfo = "门槛金额需要随着阶梯增加而增加"
							return
						} else {
							this.depreciatePromotion.discountsList[index].hintIsShow = false
						}
					}
					// 判断使用门槛必须小于20000
					if (Number(this.depreciatePromotion.discountsList[index].condition) > 20000) {
						this.depreciatePromotion.discountsList[index].hintIsShow = true
						this.depreciatePromotion.discountsList[index].hintInfo = "使用门槛必须小于20000"
						return
					} else {
						this.depreciatePromotion.discountsList[index].hintIsShow = false
					}
					// 判断门槛必须大于满减金额
					if (Number(this.depreciatePromotion.discountsList[index].condition) <= Number(this
							.depreciatePromotion
							.discountsList[index]
							.subsidy)) {
						this.depreciatePromotion.discountsList[index].hintIsShow = true
						this.depreciatePromotion.discountsList[index].hintInfo = "使用门槛必须大于满减金额"
						return
					} else {
						this.depreciatePromotion.discountsList[index].hintIsShow = false
					}
				}, 10)
			},
			// 减金额事件
			discountInputMoneyNum(index) {
				setTimeout(() => {
					// 判断门槛金额需要随着阶梯增加而增加
					if (index >= 1) {
						if (Number(this.depreciatePromotion.discountsList[index].condition) <= Number(this
								.depreciatePromotion.discountsList[index - 1].condition) || Number(this
								.depreciatePromotion.discountsList[index].subsidy) <=
							Number(this
								.depreciatePromotion.discountsList[index - 1].subsidy)) {

							this.depreciatePromotion.discountsList[index].hintIsShow = true
							this.depreciatePromotion.discountsList[index].hintInfo = "门槛金额需要随着阶梯增加而增加"
							return
						} else {
							this.depreciatePromotion.discountsList[index].hintIsShow = false
						}
					}
					// 判断使用门槛必须小于20000
					if (Number(this.depreciatePromotion.discountsList[index].condition) > 20000) {
						this.depreciatePromotion.discountsList[index].hintIsShow = true
						this.depreciatePromotion.discountsList[index].hintInfo = "使用门槛必须小于20000"
						return
					} else {
						this.depreciatePromotion.discountsList[index].hintIsShow = false
					}
					// 判断门槛必须大于满减金额
					if (Number(this.depreciatePromotion.discountsList[index].condition) <= Number(this
							.depreciatePromotion
							.discountsList[index]
							.subsidy)) {
						this.depreciatePromotion.discountsList[index].hintIsShow = true
						this.depreciatePromotion.discountsList[index].hintInfo = "使用门槛必须大于满减金额"
						return
					} else {
						this.depreciatePromotion.discountsList[index].hintIsShow = false
					}
				}, 10)
			},
			// 删除阶梯
			handleDelete(index) {
				this.depreciatePromotion.discountsList.splice(index, 1)
			},
			// 新增阶梯
			addLadder() {
				if (this.depreciatePromotion.discountsList.length < 3) {
					this.depreciatePromotion.discountsList.push({
						condition: '', //金额满、件数
						type: 1, // 活动补贴type 1、满金额减 2、满金额扣减比例 3、满金额赠 4、满件数赠    传1
						subsidy: '', // 补贴：扣减金额、扣减比例、赠送件数
						hintIsShow: false, // 提示信息是否显示
						hintInfo: '', // 提示信息
					})
				} else {
					uni.showToast({
						title: '最多添加三个阶梯',
						icon: 'none',
						duration: 1500
					})
				}
			},
			// 必选事件
			requiredChange(val) {
				this.required ? this.required = false : this.required = true
			},
			// 通过函数判断所有优惠阶梯是否都有值并且校验通过
			checkArrayObjectsProperties(array) {
				for (let i = 0; i < array.length; i++) {
					const obj = array[i];
					// 判断满金额是否为空
					if (!obj.condition) {
						this.depreciatePromotion.discountsList[i].moneyNumDataShow = true
						uni.showToast({
							title: '满减金额不能为空',
							icon: 'none',
							duration: 2000
						})
						return false
					}
					// 判断减金额是否为空
					if (!obj.subsidy) {
						this.depreciatePromotion.discountsList[i].moneyNumDataShow = true
						uni.showToast({
							title: '满减金额不能为空',
							icon: 'none',
							duration: 2000
						})
						return false
					}
					// 判断门槛金额需要随着阶梯增加而增加
					if (i >= 1) {
						if (this.depreciatePromotion.discountsList[i].condition <= this.depreciatePromotion.discountsList[
								i - 1].condition || this.depreciatePromotion.discountsList[i].subsidy <= this
							.depreciatePromotion.discountsList[i - 1].subsidy) {
							this.depreciatePromotion.discountsList[i].hintIsShow = true
							this.depreciatePromotion.discountsList[i].hintInfo = "门槛金额需要随着阶梯增加而增加"
							uni.showToast({
								title: '门槛金额需要随着阶梯增加而增加',
								icon: 'none',
								duration: 2000
							})
							return false
						}
					}
					// 判断门槛必须大于满减金额
					if (this.depreciatePromotion.discountsList[i].condition > 20000) {
						this.depreciatePromotion.discountsList[i].hintIsShow = true
						this.depreciatePromotion.discountsList[i].hintInfo = "使用门槛必须小于20000"
						uni.showToast({
							title: '使用门槛必须小于20000',
							icon: 'none',
							duration: 2000
						})
						return false
					}
					// 判断门槛必须大于满减金额
					if (Number(this.depreciatePromotion.discountsList[i].condition) <= Number(this.depreciatePromotion
							.discountsList[i].subsidy)) {
						this.depreciatePromotion.discountsList[i].hintIsShow = true
						this.depreciatePromotion.discountsList[i].hintInfo = "使用门槛必须大于满减金额"
						uni.showToast({
							title: '使用门槛必须大于满减金额',
							icon: 'none',
							duration: 2000
						})
						return false
					}
				}
				return true
			},
			// 通用赠品信息组合数据
			generalGift() {
				// 商品信息
				let activitySubsidyList = this.depreciatePromotion.discountsList.map(item => {
					// 如果有id那么  businessSign这个字段不用传
					if (this.goodsOrCategoryInfo && this.goodsOrCategoryInfo.id) {
						return {
							condition: item.condition, //条件：金额、件数
							subsidy: item.subsidy, //补贴：扣减金额、扣减比例、赠送件数
							type: item.type
						}
					} else {
						return {
							businessSign: 1, // 1添加  2编辑 3删除
							condition: item.condition, //条件：金额、件数
							subsidy: item.subsidy, //补贴：扣减金额、扣减比例、赠送件数
							type: item.type
						}
					}

				})
				this.generalGiftInfo = {
					activityCategory: 7, // 默认是店铺满赠
					activityTimeList: this.depreciatePromotion.activityTimeList, // 活动时间
					activityScopeList: this.depreciatePromotion.saleAreaList, // 售卖区域
					productScope: this.productScopeList[this.productScopeIndex].value, // 商品范围
					customerDailyLimit: this.dateLimitShopIndex == 0 ? -1 : Number(this
						.depreciatePromotion.activeLimit.dateLimitShopNum), //  单客户限制单数
					totalOrderLimit: this.totalOrderLimitIndex == 0 ? -1 : Number(this
						.depreciatePromotion.totalOrderLimitObj.totalOrderLimit), //  活动总限制单数
					activitySubsidyList: activitySubsidyList,
				}
				if (this.goodsOrCategoryInfo && this.goodsOrCategoryInfo.id) {
					this.generalGiftInfo.id = this.goodsOrCategoryInfo.id
				}
			},

			// 确认按钮
			handleNext() {
				if (!this.depreciatePromotion.saleAreaList.length) {
					return uni.showToast({
						title: '请选择售卖区域',
						duration: 1500,
						icon: 'none'
					});
				}
				if (!this.depreciatePromotion.activityTime) {
					return uni.showToast({
						title: '请选择活动时间',
						duration: 1500,
						icon: 'none'
					});
				}
				if (!this.required) {
					return uni.showToast({
						title: '请先阅读并同意《合作商自营销协议》',
						duration: 1500,
						icon: 'none'
					});
				}
				// 校验阶梯
				if (!this.checkArrayObjectsProperties(this.depreciatePromotion.discountsList)) return
				// 全店
				console.log("11")
				if (this.productScopeIndex == 0) {
					uni.showModal({
						title: '提示',
						content: '确认创建该赠品信息吗？',
						success: (res) => {
							if (res.confirm == true) {
								this.addActivityRegistration()
							} else {
								uni.showToast({
									title: '已取消',
									icon: 'none',
									duration: 2000
								})
							}
						}
					})
					// 部分商品
				} else if (this.productScopeIndex == 1) {
					// 选择部分商品
					this.selectionProduct(1)
					// 部分品类
				} else if (this.productScopeIndex == 2) {
					// 选择部分品类
					this.generalGift()
					let partGoodsList = []
					// 删除部分商品
					if (this.goodsOrCategoryInfo && this.goodsOrCategoryInfo.productScope == 1) {
						partGoodsList = this.goodsOrCategoryInfo
							.enrolledActivityProductVoList.map(item => {
								return {
									businessSign: 3,
									enrolledActivityId: item.enrolledActivityId
								}
							})
					}
					uni.navigateTo({
						url: `/pages/marketing/fullDiscountList/components/goodsCategory?generalGiftInfo=${JSON.stringify(this.generalGiftInfo)}&partGoodsList=${JSON.stringify(partGoodsList)}`,
					});
				}

			},
			// 修改开启状态
			changeIsShow(e) {
				let that = this
				let statusInfo = e.detail.value ? '开启' : '关闭'
				that.$set(that.checkedObj, 'isShow', e.detail.value)
				uni.showModal({
					title: '提示',
					content: `确认${statusInfo}吗?`,
					success: (res) => {
						if (res.confirm == true) {
							let data = {
								activityCategory: 7, // 默认是店铺满赠
								activityTimeList: that.depreciatePromotion.activityTimeList, // 活动时间
								activityScopeList: that.depreciatePromotion.saleAreaList, // 售卖区域
								productScope: that.productScopeList[that.productScopeIndex].value, // 商品范围
								customerDailyLimit: that.dateLimitShopIndex == 0 ? -1 : Number(that
									.depreciatePromotion.activeLimit.dateLimitShopNum), //  单客户限制单数
								isShow: e.detail.value
							}
							if (that.goodsOrCategoryInfo && that.goodsOrCategoryInfo.id) {
								data.id = that.goodsOrCategoryInfo.id
							}
							that.changeIsShowActivityRegistration(data, e.detail.value)
						} else {
							that.$set(that.checkedObj, 'isShow', !e.detail.value)
							uni.showToast({
								title: '已取消',
								icon: 'none',
								duration: 2000
							})
						}
					}
				})
			},
			// -------------------------------api-----------------------------------------

			// 修改开启状态功能
			async changeIsShowActivityRegistration(data, isShow) {
				let that = this
				uni.showLoading({
					title: '加载中',
					mask: true
				})
				try {
					let res = await addActivityRegistrationApi(data)
					if (res.code == 200) {
						uni.showToast({
							title: '创建成功',
							icon: 'success',
							duration: 2000
						})
						that.getNoRegistrationActivity()
					} else {
						that.$set(that.checkedObj, 'isShow', !isShow)
						uni.showToast({
							title: res.message,
							icon: 'none',
							duration: 1500
						})
					}
				} catch (e) {
					uni.showToast({
						title: e,
						icon: 'none',
						duration: 1500
					})
					//TODO handle the exception
					console.log("e", e)
				}
				uni.hideLoading()
			},
			// 添加店铺满赠活动
			async addActivityRegistration() {
				let that = this
				uni.showLoading({
					title: '加载中',
					mask: true
				})
				try {
					// 整理赠品信息
					this.generalGift()
					// 删除部分商品
					if (this.goodsOrCategoryInfo && this.goodsOrCategoryInfo.productScope == 1) {
						this.generalGiftInfo.addEnrolledActivityProductDTOList = this.goodsOrCategoryInfo
							.enrolledActivityProductVoList.map(item => {
								return {
									businessSign: 3,
									enrolledActivityId: item.enrolledActivityId
								}
							})
					}
					// 删除部分品类
					if (this.goodsOrCategoryInfo && this.goodsOrCategoryInfo.productScope == 2) {
						this.generalGiftInfo.addEnrolledActivityProductDTOList = this.goodsOrCategoryInfo
							.enrolledActivityProductVoList.map(item => {
								return {
									businessSign: 3,
									enrolledActivityId: item.enrolledActivityId
								}
							})
					}
					let res = await addActivityRegistrationApi(this.generalGiftInfo)
					if (res.code == 200) {
						uni.showToast({
							title: '创建成功',
							icon: 'success',
							duration: 2000
						})
						that.getNoRegistrationActivity()
					} else {
						uni.showToast({
							title: res.message,
							icon: 'none',
							duration: 1500
						})
					}
				} catch (e) {
					uni.showToast({
						title: e,
						icon: 'none',
						duration: 1500
					})
					//TODO handle the exception
					console.log("e", e)
				}
				uni.hideLoading()
			},
			// 获取活动商品信息
			async getNoRegistrationActivity() {
				uni.showLoading({
					title: '加载中',
					mask: true
				})
				try {
					let res = await getNoRegistrationActivityApi(7)
					if (res.code == 200) {
						this.goodsOrCategoryInfo = res.data
						// 判断是否有数据
						if (this.goodsOrCategoryInfo && this.goodsOrCategoryInfo.id) {
							this.echoData()
						}
					} else {
						uni.showToast({
							title: res.message,
							icon: 'none',
							duration: 2000
						});
					}
				} catch (e) {
					//TODO handle the exception
					uni.showToast({
						title: e,
						duration: 2000,
						icon: 'none'
					})
				}
				uni.hideLoading()
			},
			// 获取城市信息
			async getCityTreeList() {
				let that = this;
				uni.showLoading({
					title: '加载中',
					mask: true
				})
				try {
					let res = await getCityTreeListApi()
					if (res.code == 200) {
						const result = [];
						// 遍历数组中的每个对象
						for (const item of res.data) {
							// 提取对象的基本信息
							const extractedItem = {
								value: item.regionId,
								// parentId: item.parentId,
								text: item.regionName,
								// regionType: item.regionType
							};

							// 如果对象包含子对象，则将子对象的基本信息也提取出来
							if (item.child && item.child.length > 0) {
								extractedItem.children = [];
								for (const childItem of item.child) {
									const extractedChildItem = {
										value: childItem.regionId,
										// parentId: childItem.parentId,
										text: childItem.regionName,
										// regionType: childItem.regionType
									};
									extractedItem.children.push(extractedChildItem);
								}
							}
							// 将提取的对象添加到结果数组中
							result.push(extractedItem);
						}
						this.cityCodeList = result; // 二级城市下分类
					} else {
						uni.showToast({
							title: res.message,
							icon: 'none',
							duration: 1500
						})
					}
				} catch (e) {
					uni.showToast({
						title: e,
						icon: 'none',
						duration: 1500
					})
					console.log("e", e)
					//TODO handle the exception
				}
				uni.hideLoading()
			},
		}
	}
</script>
<style lang="scss">
	page {
		height: 100%;


	}

	.font_color {
		@include main_color(theme);
	}

	.container {
		display: flex;
		flex-direction: column;
		height: 100%;
	}

	.header {}

	.content {
		flex: 1;
		overflow: hidden;
	}

	.scroll-view {
		height: 100%;
	}

	// 赠送类型
	.gift-type-card {
		display: flex;
		flex-direction: column;
		padding: 0 20rpx;
		padding-bottom: 20rpx;

		.gift-type {
			display: flex;
			background-color: white;
			padding: 30rpx 20rpx;
			border-radius: 10rpx;

			.gift-type-left {
				font-weight: bold;

			}

			.gift-type-right {
				font-weight: bold;
				display: flex;
				flex-direction: column;
			}
		}
	}

	.scroll-view-inner {

		// 售卖区域
		.sale-area-card {
			display: flex;
			flex-direction: column;
			padding: 0 20rpx;

			.sale-area {
				display: flex;
				background-color: white;
				justify-content: space-between;
				align-items: center;
				padding: 30rpx 20rpx;
				border-radius: 10rpx;

				.sale-area-left {
					font-weight: bold;
				}

				.sae-area-right {
					font-weight: bold;
					display: flex;
					flex-direction: column;
				}
			}
		}



		// 商品活动
		.product-active-card {
			display: flex;
			flex-direction: column;
			padding: 20rpx;

			// 活动时间
			.active-time {
				display: flex;
				justify-content: space-between;
				background-color: white;
				padding: 30rpx 20rpx;
				border-radius: 10rpx;
				border-bottom: 1rpx solid #eee;

				.active-time-left {
					font-weight: bold;
				}

				.active-time-right {
					display: flex;
				}
			}

			// 活动范围
			.product-scope {
				display: flex;
				justify-content: space-between;
				align-items: center;
				background-color: white;
				padding: 30rpx 20rpx;
				border-radius: 10rpx;
				border-bottom: 1rpx solid #eee;

				.product-scope-left {
					font-weight: bold;
				}

				.product-scope-right {
					display: flex;

					.product-type {
						border: 1rpx solid #eaeaea;
						margin-left: 20rpx;
						padding: 10rpx 20rpx;
						border-radius: 10rpx;
					}

					.active {
						border: 1rpx solid;
						@include border_color(theme);
						@include main_color(theme);
					}
				}
			}

			// 单客户限购单数
			.active-limit-card {
				display: flex;
				flex-direction: column;
				background-color: white;
				padding: 30rpx 20rpx;
				border-radius: 10rpx;

				.active-limit-top {
					display: flex;
					justify-content: space-between;
					align-items: center;

					.active-limit-left {
						font-weight: bold;
					}

					.active-limit-right {
						display: flex;
						// justify-content: flex-end;
						justify-content: space-between;

						.active-type {
							border: 1rpx solid #eaeaea;
							padding: 10rpx 20rpx;
							border-radius: 10rpx;
							margin-left: 20rpx;
						}

						.active {
							border: 1rpx solid;
							@include border_color(theme);
							@include main_color(theme);
						}

					}
				}

				.active-limit-bottom {
					display: flex;
					display: flex;
					justify-content: flex-end;
					padding: 20rpx 0;
				}

				.discounts-hint {
					display: flex;
					justify-content: flex-end;
					color: red;
				}

			}
		}

		// 优惠阶梯
		.discounts-card {
			.discounts-item {
				display: flex;
				flex-direction: column;
				margin: 0 20rpx;
				margin-bottom: 20rpx;
				padding: 0 20rpx;
				background-color: white;


				.discounts-item-title {
					padding: 20rpx 0;
					font-weight: bold;
					display: flex;
					justify-content: space-between;
					align-items: center;

					.item-title-left {
						width: 200rpx;
						flex-shrink: 0;
					}

					.item-title-right {
						display: flex;

						.price-left {
							display: flex;
							align-items: center;

							.price-num {
								display: flex;
								align-items: center;

								.right-input {
									margin-left: 10rpx;
									background-color: #faf8fa;
									padding: 10rpx;
									height: 60rpx;
									margin-right: 20rpx;
								}
							}
						}
					}
				}

				.discounts-hint {
					color: red;
					display: flex;
					justify-content: flex-end;
					padding: 20rpx;
				}
			}
		}

		// 新增阶梯
		.ladder-card {
			background-color: white;
			padding: 35rpx;
			margin: 20rpx;
			text-align: center;
		}


	}

	// 底部按钮
	.footer {
		.bg_color {
			@include main_bg_color(theme);
			color: white;
		}

		.font_color {
			@include main_color(theme)
		}

		.footer-required {
			display: flex;
			align-items: center;
			margin-bottom: 20rpx;
		}

		background-color: white;
		padding: 10rpx 20rpx;
		margin-top: 20rpx;
	}
</style>